package com.benny_driving_dri.act.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.benny_driving_dri.R;
import com.benny_driving_dri.entity.Sug;

public class FeedBackAdapter extends BaseAdapter {
	private LayoutInflater layoutInflater = null;
	private List<Sug> listSug = null;

	public FeedBackAdapter(List<Sug> listSug, Context context) {
		layoutInflater = LayoutInflater.from(context);
		this.listSug = listSug;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listSug.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return listSug.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = layoutInflater.inflate(R.layout.adapter_feedback,
					parent, false);
			holder.driPhn = (TextView) convertView
					.findViewById(R.id.feedBack_tv_Phn);
			holder.driCon = (TextView) convertView
					.findViewById(R.id.feedBack_tv_Con);
			holder.driTime = (TextView) convertView
					.findViewById(R.id.feedBack_tv_DriTime);
			holder.ourCon = (TextView) convertView
					.findViewById(R.id.feedBack_tv_OurCon);
			holder.ourTime = (TextView) convertView
					.findViewById(R.id.feedBack_tv_OurTime);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		initView(holder, position);
		return convertView;
	}

	private void initView(ViewHolder holder, int position) {
		holder.driPhn.setText(listSug.get(position).getTel());
		holder.driCon.setText(listSug.get(position).getContent());
		holder.driTime.setText(listSug.get(position).getTime());
		holder.ourCon.setText(listSug.get(position).getRcontent());
		holder.ourTime.setText(listSug.get(position).getRtime());
	}

	class ViewHolder {
		TextView driPhn, driCon, driTime, ourCon, ourTime;
	}
}